package designMode.iteratorPattern;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author LIBOFEI
 * @ClassName DinnerHouseMenu
 * @description  另一个菜单的实现，使用数组实现数据存储
 * @date 2020/6/26 16:08
 * @Version 1.0
 **/
public class DinnerHouseMenu implements MenuIterator{

    private static final int MAX_SIZE = 5;
    private int index = 0;
    private MenuItem[] menuItems;

    public DinnerHouseMenu(){
        menuItems = new MenuItem[MAX_SIZE];
        for(int i = 0; i < MAX_SIZE ; i++){
            addItem("dinnerName" + i, "dinnerContent" + i, true,i);
        }
    }

    public void addItem(String name,String description,boolean vegetarian,double price){
        MenuItem menuItem = new MenuItem(name,description,vegetarian,price);
        if((((index > MAX_SIZE)))){
            System.out.println("数组已满");
            return;
        }
        menuItems[index] = menuItem;
        index++;
    }

    public MenuItem[] getMenuItems() {
        return menuItems;
    }

    /** *
     * 迭代器模式，创建迭代器，返回
     * @author LIBOFEI
     * @date 16:35 2020/6/26
     * @return designMode.iteratorPattern.Iterator
     * @Version  1.0
    **/
    @Override
    public java.util.Iterator createIterator(){
        return new DinnerHouseMenuIterator(menuItems);
    }

    @Override
    public String toString() {
        return "DinnerHouseMenu{" +
                "index=" + index +
                ", menuItems=" + Arrays.toString(menuItems) +
                '}';
    }


}
